package com.onenine.app.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.onenine.app.R;
import com.onenine.app.model.GameRoom;
import com.onenine.app.utils.CHelper;
import com.onenine.app.utils.DataType;
import com.onenine.app.utils.GlideUtils;
import com.onenine.app.utils.RoleResLoader;
import com.onenine.common.util.ApUtils;

import java.util.ArrayList;

public class GameRoomAdapter extends BaseQuickAdapter<GameRoom, BaseViewHolder> {

    private Context mContext;
    private int mPhotoSize;

    public GameRoomAdapter(int photoSize) {
        super(R.layout.layout_game_room_item, new ArrayList<>());
        mContext = ApUtils.getApp();
        mPhotoSize = photoSize;
    }

    @Override
    protected void convert(BaseViewHolder helper, GameRoom item) {
        ImageView ivPhoto = helper.getView(R.id.iv_photo);
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) ivPhoto.getLayoutParams();
        params.width = ViewGroup.LayoutParams.MATCH_PARENT;
        params.height = mPhotoSize;
        GlideUtils.loadSrcImage(ApUtils.getApp(), ivPhoto, CHelper.getFullPlatformThumbImageUrl(item.getPhoto(), mPhotoSize));
        RadioButton tvIntro = helper.getView(R.id.tv_introduce);
        tvIntro.setText(item.getIntroduce());
        tvIntro.setButtonDrawable(item.getGamePattern() == GameRoom.GAME_MODE_TEXT ? R.drawable.ic_game_text_mode
                : item.getGamePattern() == GameRoom.GAME_MODE_VOICE ? R.drawable.ic_game_voice_mode : R.drawable.ic_game_video_mode);
        TextView tvName = helper.getView(R.id.tv_name);
        tvName.setText(item.getNickName());
        tvName.setCompoundDrawablesWithIntrinsicBounds(0, 0
                , RoleResLoader.getRoleDrawableResourceId(RoleResLoader.DynamicResName.IC_GAME_ITEM_SEX, item.getSex()), 0);
        TextView tvCoin = helper.getView(R.id.tv_coin_count);
        TextView tvLimit = helper.getView(R.id.tv_sex_limit);
        tvCoin.setText(mContext.getString(R.string.diamond_count_format, item.getBetNum()));
        tvCoin.setBackgroundResource(RoleResLoader
                .getRoleDrawableResourceId(RoleResLoader.DynamicResName.IC_GAME_AMOUNT_COUNT_BG, item.getSex()));
        if (item.getPlayerRestrict() == DataType.SEX_MALE) {
            tvLimit.setText(R.string.limit_male);
        } else if (item.getPlayerRestrict() == DataType.SEX_FEMALE) {
            tvLimit.setText(R.string.limit_female);
        } else {
            tvLimit.setText(R.string.limit_no);
        }
    }

}
